/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 16:06:20
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-04-23 17:30:13
 */
import { uploadType } from '@/utils/util'
import { getStore } from '@/utils/store'
let userInfo = getStore('userInfo')
// 判断是服务商还是民政
let userType = 'govUser'
if(userInfo.classifyId==5){
	// 服务商
	userType = 'providerUser'
}else if(userInfo.classifyId==3){
	//民政用户
	userType = 'govUser'
}

export const TRAIN_LEVEL = [
	{ label: '国家级', value: '0', type: 'primary' },
	{ label: '省级', value: '1', type: 'primary' },
	{ label: '市级', value: '2', type: 'primary' },
	{ label: '区级', value: '3', type: 'primary' },
]
export const TASK_STATUS = [
	{ label: '未开始', value: '0', type: 'primary' },
	{ label: '进行中', value: '1', type: 'primary' },
	{ label: '已结束', value: '2', type: 'primary' },
]
export const APPROVAL_STATUS = [
	{ label: '待处理', value: '0', type: 'primary' },
	{ label: '待审批', value: '1', type: 'primary' },
	{ label: '审批通过', value: '2', type: 'primary' },
	{ label: '审批驳回', value: '3', type: 'primary' },
]

// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '培训名称', prop: 'trainingName' },
		{ label: '组织名称', prop: 'organizationName' },
		{ label: '组织单位', prop: 'createUserName' },
		{
			label: '报名时间',
			prop: 'signUpTime',
		},
		{
			label: '培训类型',
			custome: 'tag',
			prop: 'trainingType',
			code: 'TRAIN_SUPER_TRAIN_TYPE',
			api: 'getDictItemList',
		},
		{ label: '培训单位名称', prop: 'trainingUnitName' },
		{
			label: '培训课时',
			prop: 'courseHours',
		},
		{
			label: '培训层级',
			prop: 'trainingLevel',
			custome: 'tag',
			dicData: TRAIN_LEVEL,
		},
		{
			label: '任务状态',
			prop: 'taskStatus',
			custome: 'tag',
			dicData: TASK_STATUS,
		},
		{
			label: '审批状态',
			prop: 'approvalStatus',
			custome: 'tag',
			dicData: APPROVAL_STATUS,
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}
const formConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	column:[
		{
			label:"培训名称",
			prop:"trainingName",
			span:24,
			rules:[
				{required:true,message:"请填写培训名称"}
			]
		},
		{
			label:"培训单位",
			prop:"unitCreditCode",
			propName: 'trainingUnitName',
			type: 'autoSelect',
			api: 'view_dpServiceProvider_page',
			filterKey: 'creditCode',
			filterLabel: 'providerName',
			multiple: false,
			placeholder: '请输入培训单位',
			paramsObj: {
				code: 3019
				// roleName: '安全员',
			},
			rules:[
				{required:true,message:"请填写培训单位"}
			],
			span:24
		}
	]
}

export const api = {
	index: 'view_bscTrainingManagement_page',
	add: 'view_bscTrainingManagement_add',
	edit: 'view_bscTrainingManagement_edit',
	delete: 'view_bscTrainingManagement_del',
}
export const formateBuilData = (form) => {
	let query = {
		...form,
		buildInfo: undefined,
	}
	if (form.buildInfo && form.buildInfoText) {
		query.checkinBuilding = form.buildInfo[0]
		query.checkinFloor = form.buildInfo[1]
		query.checkinRoom = form.buildInfo[2]
		query.checkinBed = form.buildInfo[3]
	}
	return query
}

export const baseConfig = {
	pageName: '年度总任务管理',
	// 数据字典
	dictcodes: ['GOVERNMENT_MAIN_STATUS'],
	rowKey: 'id',
	tipLabel: 'taskName',
	addLabel: '制定培训单位',
	api: {
		...api,
	},
	auth: {
		...api,
		mulitSet: 'mulitSet',
	},
	menuAction: [
		{
			label: '预约入住',
			type: 'primary',
			operate: 'appoint',
			auth: 'view_dpElderlyCheckinRecord_page',
			show: false,
		},
	],
	// 当前行操作按钮
	menuBtn: [
		{
			label: '详情',
			type: 'primary',
			operate: userType == 'providerUser'?'providerDetail':'govDetail',
			auth: api.index,
			text: true,
			show: true,
		},
		{
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: api.edit,
			text: true,
			show: true,
		},
		{
			label: '删除',
			type: 'danger',
			operate: 'delete',
			condition: "(row)=>(row.taskStatus=='CREATED'||row.taskStatus=='UNFILLED')",
			auth: api.delete,
			text: true,
			show: true,
		},
		{
			label: '反馈',
			type: 'primary',
			operate: 'callback',
			condition: "(row)=>(row.taskStatus=='CREATED'||row.taskStatus=='UNFILLED')",
			auth: api.delete,
			text: true,
			show: true,
		},
	],
	formConfig,
	dialogConfig: {
		width: '80%',
	},
	// 搜索
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{ label: '培训名称', prop: 'trainingName', type: 'input', span: 8 },
			{ label: '组织单位', prop: 'organizationName', type: 'input', span: 8 },
			{
				label: '报名时间',
				prop: 'signUpTime',
				type: 'daterange',
				format: 'YYYY年MM月DD',
				valueFormat: 'YYYY-MM-DD',
				span: 8,
			},
			{
				label: '培训类型',
				type: 'remoteSelect',
				prop: 'trainingType',
				propName: 'trainingTypeLabel',
				code: 'TRAIN_SUPER_TRAIN_TYPE',
				api: 'getDictItemList',
				span: 8,
			},
			{
				label: '任务状态',
				prop: 'taskStatus',
				propName: 'taskStatusLabel',
				type: 'select',
				dicData: TASK_STATUS,
				span: 8,
			},
			{
				label: '培训层级',
				prop: 'trainingLevel',
				propName: 'trainingLevelLabel',
				type: 'select',
				dicData: TRAIN_LEVEL,
				span: 8,
			},
			{ label: '培训单位名称', prop: 'trainingUnitName', span: 8 },
		],
	},
	// 列表
	tableConfig,

	onLoadFormate: async (arr) => {
		let tableData = arr.map((item) => {
			if(item.signUpStartTime&&item.signUpEndTime){
				item.signUpTime = [item.signUpStartTime,item.signUpEndTime]
			}
			return item
		})
		return Promise.resolve(tableData)
	},
	beforeOnLoadFormate(form) {
		// 处理搜索条件
		if(form.signUpTime){
			form.signUpStartTime = form.signUpTime[0]
			form.signUpEndTime = form.signUpTime[1]
			form.signUpTime = undefined
		}
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
}
